package com.yoso.base.service;

import com.yoso.base.infrastructure.constants.ResponseCode;
import com.yoso.base.interfaces.controller.BaseResponse;

/**
 * @author zhizejin
 */
public abstract class AbstractService {
    protected <T> BaseResponse<T> success(T data) {
        return BaseResponse.success(data);
    }

    protected BaseResponse<Void> success(String msg) {
        return BaseResponse.success(msg);
    }

    protected <T> BaseResponse<T> success(String msg, T data) {
        return BaseResponse.success(msg, data);
    }

    protected BaseResponse<Void> success() {
        return BaseResponse.success();
    }

    protected BaseResponse<Void> error(String msg) {
        return new BaseResponse<>(ResponseCode.ERROR, null, msg, false);
    }

    protected BaseResponse<Void> result(int result) {
        if (result == 1) {
            return BaseResponse.success();
        }
        return BaseResponse.error();
    }
}
